package com.eric.controller;

import com.eric.test.socket.WebSocketServer;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/test")
public class WebSocketController {



    @Resource
    WebSocketServer webSocketServer;

    /**
     * 启动页面
     * @return
     */
    @GetMapping("/start")
    public String start(){
        return "index";
    }

    @PostMapping("/pushToWeb")
    @ApiOperation(value = "服务器端向客户端推送消息", notes = "服务器端向客户端推送消息")
    public void pushToWeb(String message ,String userId){
        WebSocketServer.sendInfo(message,userId);
    }

}
